/*
 * RSASignatureAlgorithmSelectorDialog.java
 *
 * Created on 24. September 2008, 19:54
 */

package jcrypter.signature;

/**
 *
 * @author  uli
 */
public class RSASignatureAlgorithmSelectorDialog extends javax.swing.JDialog {
    
    /** Creates new form RSASignatureAlgorithmSelectorDialog */
    public RSASignatureAlgorithmSelectorDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        //Add standard associations
        //Set the default
        digestComboBox.setSelectedItem("SHA256");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        digestLabel = new javax.swing.JLabel();
        digestComboBox = new javax.swing.JComboBox();
        okButton = new javax.swing.JButton();
        pssCheckbox = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Select RSA algorithm");

        digestLabel.setText("Digest:");

        digestComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MD2", "MD4", "MD5", "RIPEMD128", "RIPEMD160", "RIPEMD256", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512" }));

        okButton.setText("OK");
        okButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                okButtonMouseClicked(evt);
            }
        });

        pssCheckbox.setSelected(true);
        pssCheckbox.setText("PSS");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(okButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(digestLabel)
                        .addGap(18, 18, 18)
                        .addComponent(digestComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(pssCheckbox)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(digestLabel)
                    .addComponent(digestComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pssCheckbox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(okButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void okButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okButtonMouseClicked
    //Set the padding string depending on the combo box selection
    this.setVisible(false);
}//GEN-LAST:event_okButtonMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                RSASignatureAlgorithmSelectorDialog dialog = new RSASignatureAlgorithmSelectorDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    public String getAlgorithm()
    {
        if(pssCheckbox.isSelected())
            {return (String) digestComboBox.getSelectedItem() + "WithRSAandMGF1";}
        return (String) digestComboBox.getSelectedItem() + "WithRSA";
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox digestComboBox;
    private javax.swing.JLabel digestLabel;
    private javax.swing.JButton okButton;
    private javax.swing.JCheckBox pssCheckbox;
    // End of variables declaration//GEN-END:variables
}
